import _ from 'lodash'
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

Vue.config.productionTip = false
const ws_url = _.get(window, "wsc_ws_url", "http://localhost:13001");


import SocketIOInstall from '@/plugins/socket-io-install'
import { SocketInfo } from '@/types/socket-io-model'
Vue.use(SocketIOInstall, ws_url);
console.log({ ws_url });
// import SocketIO from 'socket.io-client'
// import VueSocketIO from 'vue-socket.io'
// Vue.use(new VueSocketIO(
//     debug: true,
//     connection: SocketIO("http://localhost:13001")
// ));


new Vue({
    router,
    store,
    render: h => h(App),
    created() {
        this.$store.dispatch("init");

        this.$socket.on("connect", () => {
        });

        this.$socket.on("conn-info", (si?: SocketInfo) => {
            if (si) {
                this.$store.commit("user_info/set_id", si.id);
                this.$store.commit("connection/set_socket_code", si.socket_code);
            }
        })

        this.$socket.on('disconnect', () => {
            console.log("断开连接！")
            this.$router.push("/");
        });
    }
}).$mount('#app')
